// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import NetAdapter from "../../adpapter/NetAdapter";
import GlobalData from "../../GlobalData";
import { Util } from "../../utils/Util";

const {ccclass, property} = cc._decorator;

@ccclass
export default class ChaxunItem extends cc.Component {

    @property({

        displayName:"搜索UID",
        type:cc.EditBox
    })
    editbox_uid: cc.EditBox = null;

    @property({
        displayName: "uid",
        type: cc.Label
    })
    label_uid: cc.Label = null;

    @property({
        displayName: "注册时间",
        type: cc.Label
    })
    label_register_time: cc.Label = null;

    @property({
        displayName: "代理UID",
        type: cc.Label
    })
    label_daili_uid: cc.Label = null;

    @property({
        displayName: "今日观看广告次数",
        type: cc.Label
    })
    adv_viewed_num: cc.Label = null;

    @property({
        displayName: "搜索结果",
        type: cc.Node
    })
    node_search_result: cc.Node = null;

    @property({
        displayName: "搜索出错节点",
        type: cc.Node
    })
    node_search_error: cc.Node = null;

    @property({
        displayName: "搜索出错",
        type: cc.Label
    })
    label_search_error: cc.Label = null;
    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    start () {

    }

    initItem(){
        this.node_search_result.active = false;
        this.node_search_error.active = true;
        this.label_search_error.string = "请输入UID";
    }
    searchUser(){
        NetAdapter.getUserById({
            uid_want: this.editbox_uid.string
        }).then((res) => {
            console.log(res);
            // if(res.code == 0){
                // this.label_uid.string = res.info.uid;
                this.label_uid.string = res.id;
                this.label_daili_uid.string = res.agent_uid==0?"暂无代理":res.agent_uid;
                this.label_register_time.string = Util.convertTimestampToDateTime(res.create_time);
                this.adv_viewed_num.string = res.adv_viewed_num;
                this.node_search_result.active = true;
                this.node_search_error.active = false;
            // }else{
            //     this.node_search_result.active = false;
            //     this.node_search_error.active = true;
            //     this.label_search_error.string = '请输入正确的UID';
            // }
        }).catch(err=>{
            this.node_search_result.active = false;
            this.node_search_error.active = true;
            this.label_search_error.string = '请输入正确的UID'; 
        })
    }
    // update (dt) {}
}
